package com.ecloud.support.generator.controller;

import java.io.IOException;

import javax.annotation.Resource;

import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ecloud.common.base.result.Result;
import com.ecloud.common.base.valid.ValidGroup.Insert;
import com.ecloud.common.base.valid.ValidGroup.QueryOne;
import com.ecloud.support.generator.model.dto.TableConfigDto;
import com.ecloud.support.generator.model.dto.TableConfigDto.Generates;
import com.ecloud.support.generator.service.iface.ITableConfigService;

@RestController
@RequestMapping({ "/table/config" })
public class TableConfigController {
    @Resource
    private ITableConfigService service;

    /**
     * 生成代码 支持单表
     *
     * @author LiuGangQiang Create in 2021/04/01
     * @param dto 入参
     * @return {@link Result}
     * @throws IOException
     */
    @PostMapping("/generate")
    public ResponseEntity<byte[]> generator(@Validated({ Insert.class }) TableConfigDto dto) throws IOException {
        return service.generator(dto);
    }

    /**
     * 生成代码 支持多表表
     *
     * @author LiuGangQiang Create in 2021/04/01
     * @param dto 入参
     * @return {@link Result}
     * @throws IOException
     */
    @PostMapping("/generates")
    public ResponseEntity<byte[]> generators(@Validated({ Generates.class }) TableConfigDto dto) throws IOException {
        return service.generators(dto);
    }

    /**
     * 保存配置
     *
     * @author LiuGangQiang Create in 2021/05/16
     * @param dto 入参
     * @return {@link Result}
     */
    @PostMapping("/config")
    public Result<?> insert(@RequestBody @Validated({ Insert.class }) TableConfigDto dto) {
        return service.insert(dto);
    }

    /**
     * 查询详情
     *
     * @author LiuGangQiang Create in 2021/04/01
     * @param id ID
     * @return {@link Result}
     */
    @GetMapping("/config")
    public Result<?> queryDetail(@Validated({ QueryOne.class }) TableConfigDto dto) {
        return service.queryDetail(dto);
    }
}
